Skip to content

Conversation

yeyu-nvidia
Copy link
Contributor

@yeyu-nvidia yeyu-nvidia commented Sep 5, 2025

What does this PR do?

Type of change: Bug fix

Overview:
pipeline_dtype was set to None in current main which blocks PP usage in Megatron. We set to params_dtype to fix it.

Usage

# Add a code snippet demonstrating how to use this

Testing

Before your PR is "Ready for review"

  • Make sure you read and follow Contributor guidelines and your commits are signed.
  • Is this change backward compatible?: Yes/No
  • Did you write any new necessary tests?: Yes/No
  • Did you add or update any necessary documentation?: Yes/No
  • Did you update Changelog?: Yes/No

Additional Information

Summary by CodeRabbit

  • Bug Fixes
    • Ensures the model pipeline consistently uses the configured tensor data type, reducing dtype mismatches and potential runtime errors.
    • Improves stability and consistency across architectures by aligning pipeline precision with configuration settings.

@yeyu-nvidia yeyu-nvidia requested a review from a team as a code owner September 5, 2025 16:44
Copy link

coderabbitai bot commented Sep 5, 2025

Walkthrough

Updated dict_to_config in the Megatron-Eagle speculative plugin to set TransformerConfig.pipeline_dtype using architecture_config["torch_dtype"] via getattr(torch, ...). Previously it was None. No function signature or other field assignments changed. No public API modifications.

Changes

Cohort / File(s) Summary
Speculative Megatron-Eagle plugin config
modelopt/torch/speculative/plugins/megatron_eagle.py
Set pipeline_dtype to torch. from architecture_config["torch_dtype"] via getattr; previously None. Other TransformerConfig fields unchanged; no signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my nose at dtypes bright,
From None to torch, aligned just right.
Pipelines hum, configs agree,
A tidy hop in harmony.
Carrot commits, and onward—whee! 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch yeyu/add_pipeline_dtype_to_megatron_config

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
modelopt/torch/speculative/plugins/megatron_eagle.py (1)

78-96: Deduplicate dtype resolution and accept torch.dtype directly.

Resolve torch_dtype once and reuse to avoid drift if resolution logic changes. Also handle the case where architecture_config["torch_dtype"] is already a torch.dtype.

Apply:

@@
 def dict_to_config(
@@
 ):
     """Helper function to convert a dictionary to TransformerConfig."""
-    config = TransformerConfig(
+    dtype = architecture_config.get("torch_dtype")
+    if isinstance(dtype, str):
+        dtype = getattr(torch, dtype)
+    elif not isinstance(dtype, torch.dtype):
+        raise ValueError(f"Unsupported torch_dtype: {dtype!r}")
+
+    config = TransformerConfig(
@@
-        params_dtype=getattr(torch, architecture_config["torch_dtype"]),
-        pipeline_dtype=getattr(torch, architecture_config["torch_dtype"]),
+        params_dtype=dtype,
+        pipeline_dtype=dtype,
         num_layers=architecture_config.get("num_hidden_layers"),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2b52759 and e1a0d30.

📒 Files selected for processing (1)
  • modelopt/torch/speculative/plugins/megatron_eagle.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: linux
  • GitHub Check: wait-checks / wait
  • GitHub Check: code-quality
  • GitHub Check: build-docs
🔇 Additional comments (2)
modelopt/torch/speculative/plugins/megatron_eagle.py (2)

92-94: Good fix: pipeline_dtype now aligned with params_dtype.

Setting pipeline_dtype stops PP from being blocked by None and matches params_dtype by construction. Looks correct.


79-108: Verify pipeline_dtype support in TransformerConfig
Ensure the megatron.core version in your CI environment accepts the pipeline_dtype parameter in TransformerConfig.__init__; if not, remove or guard its use.

Copy link
Collaborator

@ChenhanYu ChenhanYu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

codecov bot commented Sep 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.94%. Comparing base (76fb12d) to head (e1a0d30).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #291      +/-   ##
==========================================
- Coverage   73.95%   73.94%   -0.01%     
==========================================
  Files         172      172              
  Lines       17405    17405              
==========================================
- Hits        12871    12870       -1     
- Misses       4534     4535       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yeyu-nvidia yeyu-nvidia merged commit 8a07376 into main Sep 5, 2025
20 checks passed
@yeyu-nvidia yeyu-nvidia deleted the yeyu/add_pipeline_dtype_to_megatron_config branch September 5, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants